﻿--获取政策发布List(多单位)
CREATE PROCEDURE [dbo].[proc_Policy_GetList_s]
(
	@CompanyId int,
	@Title nvarchar(200),
	@StartIndex int,
	@EndIndex int
)
as	
	Begin


	    update Policy set IsEnd=1 where EndTime<GETDATE() --当前时间大于到期时间，则这条政策已过期

		;WITH list As(Select ROW_NUMBER() OVER (Order By UpTime desc,IsEnd asc,EndTime desc,IsDing desc)AS Row,
			N.Id,
			N.NId,
			N.Fid,
			isnull((select title from Policy_Category where id=N.fid),'未知') as category,
			N.Title,
			N.Content,
			(select e.ename from employee e where e.username = n.upname) as UpName,
			N.IsAll,
			N.IsDing,
			N.IsEnd,
			N.CreateTime,
			N.UpTime,
			N.EndTime
		From Policy N 
		--Where (@CompanyId=0 Or CompanyId=@CompanyId OR CompanyIdList LIKE '%'+'{'+convert(VARCHAR,@CompanyId)+'}'+'%') And (@Title is null Or N.Title like '%'+ @Title +'%')
		Where (@CompanyId=0 Or CompanyIdList LIKE '%{'+convert(VARCHAR(10),@CompanyId)+'}%') And (@Title is null Or N.Title like '%'+ @Title +'%')  
		)
		
		Select *,(SELECT Count(1) From list ) AS cid From list
		 Where Row between @StartIndex and @EndIndex
	End
